class_name Enemy extends CharacterBody2D

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
enum Direction {LEFT = -1, RIGHT = 1}
# 设置运动方向
@export var direction:Direction = Direction.LEFT
# 设置面部朝向
var face_direction:Direction = Direction.LEFT

# 反转朝向 - 如果怪物图片不是向左的，那么需要反转
@export var face_reverse:bool = false

@export var max_speed = 50
@export var acceleration= 50/0.2
@export var is_death:bool = false

@onready var sprite:Sprite2D = $Sprite2D
@onready var animation_player:AnimationPlayer = $AnimationPlayer

func _ready():
	set_face_direction(direction)
	
func _on_hurt_box_hurt(hit_box):
	if hit_box.instant_kill:
		queue_free()
	elif animation_player.has_animation("death"):
		animation_player.play("death")
	else:
		queue_free()

func _on_visible_on_screen_enabler_2d_screen_entered():
	var enable = $VisibleOnScreenEnabler2D
	enable.queue_free()
	#queue_free()

# 设置面部朝向
func set_face_direction(_face_direction):
	face_direction = _face_direction
	
	# 精灵朝向
	sprite.flip_h = face_direction < 0
	
	# 精灵朝向
	if face_reverse:
		sprite.flip_h = face_direction < 0
	else:
		sprite.flip_h = face_direction > 0
		
func was_killed():
	pass


